'''
'''

import types
from SimpleCells.Components.Table.SCDataAtom import SCDataAtom

class SCTableData(object):
    '''The base data container contained in SCTableModel.
    '''
    def __init__(self, nRows = 100, nCols = 20):
        '''
        @param nRows, the number of rows
        @param nCols, the number of cols
        '''
        self.__data = []
        for _1 in range(nRows):
            self.__data.append([])
            for _2 in range(nCols):
                self.__data[-1].append(SCDataAtom())

    def __getitem__(self,index):
        '''Accessing data elements using QModelIndex.
        @param index, QModelIndex
        '''
        return self.__data[index.row()][index.column()]
    
    def __setitem__(self,index,value):
        '''
        '''
        self.__data[index.row()][index.column()] = value
    
    def __delitem__(self,index):
        del self.__data[index.row()][index.column()]

    def __iter__(self):
        return iter(self.__data)

    def __call__(self,row,col):
        return self.__data[row][col]

    def nRows(self):
        return len(self.__data)
    
    def nCols(self):
        return len(self.__data[0])
    
    def delRow(self,row):
        del self.__data[row]
    
    def delCol(self,col):
        for row in self.__data:
            del row[col]
    
    def addRows(self,rows):
        for _1 in range(rows):
            self.__data.append([SCDataAtom(),]*self.nCols())
        return True
    
    def addCols(self,cols):
        for i in range(self.nRows()):
            self.__data[i] += ([SCDataAtom(),]*cols)
        return True

    def getRawTable(self):
        out = []
        for i in range(self.nRows()):
            out.append([])
            for j in range(self.nCols()):
                out[-1].append(self.__data[i][j].rawData)
        return out

    def setRawTable(self,rawTable):
        rows, cols = len(rawTable), len(rawTable[0])
        self.__data = []
        for i in range(rows):
            self.__data.append([])
            for j in range(cols):
                self.__data[-1].append(SCDataAtom(rawTable[i][j]))

if __name__ == '__main__':
    pass